package main

import (
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/service"
	"github.com/zeromicro/go-zero/zrpc"
	"go-zero-admin/application/job/rpc/internal/config"
	taskscheduleserviceServer "go-zero-admin/application/job/rpc/internal/server/taskscheduleservice"
	"go-zero-admin/application/job/rpc/internal/svc"
	job "go-zero-admin/application/job/rpc/pb"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

var configFile = flag.String("f", "etc/job.yaml", "the config file")

func main() {
	flag.Parse()

	conf.MustLoad(*configFile, &config.Conf)
	ctx := svc.NewServiceContext(config.Conf)

	s := zrpc.MustNewServer(config.Conf.RpcServerConf, func(grpcServer *grpc.Server) {
		job.RegisterTaskScheduleServiceServer(grpcServer, taskscheduleserviceServer.NewTaskScheduleServiceServer(ctx))
		if config.Conf.Mode == service.DevMode || config.Conf.Mode == service.TestMode {
			reflection.Register(grpcServer)
		}
	})
	defer s.Stop()
	fmt.Printf("Starting rpc server at %s...\n", config.Conf.ListenOn)
	s.Start()
}
